<template>
  <div class="file-review">
    <div class="img-rev" v-if="mode === 'img'">
      <div class="overlay"></div>
      <img :src="url" alt="" width="70%" />
    </div>
  </div>
</template>

<script>
import { canReviewFileMap } from "@/staticLists/public";
export default {
  name: "fileReview",
  data() {
    return {
      url: "",
      mode: "",
      canReviewFileMap,
    };
  },
  mounted() {
    // 文件预览 https://blog.csdn.net/m0_51223745/article/details/133879923
    this.url = this.$route.query.url;
    let list = this.url.split(".");
    for (const key in this.canReviewFileMap) {
      if (Object.hasOwnProperty.call(this.canReviewFileMap, key)) {
        const element = this.canReviewFileMap[key];
        if (element.includes(list[list.length - 1])) {
          this.mode = key;
          break;
        }
      }
    }
  },
};
</script>

<style lang="less" scoped>
.file-review {
  .img-rev {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    .overlay {
      width: 100vw;
      height: 100vh;
      position: absolute;
      top: 0;
      left: 0;
      background-color: rgba(0, 0, 0, 0.5);
    }
  }
}
</style>